﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;
using System.Windows.Media;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.Call"/>.
    /// </summary>
    public class CallVM : ArgumentsOperatorVM
    {
        #region /* STATICS */

        internal static void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(Call),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new CallVM((Call)codeObject, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.Call"/>.
        /// </summary>
        public CallVM(Call call, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(call, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.Call"/> model.
        /// </summary>
        public Call Call
        {
            get { return (Call)CodeObject; }
        }

        #endregion

        #region /* RENDERING */

        protected override void RenderName(CodeRenderer renderer, RenderFlags flags)
        {
            _expressionVM.Render(renderer, flags);
        }

        protected override void RenderStartArguments(CodeRenderer renderer, Brush brush, RenderFlags flags)
        {
            if (!MethodDeclBaseVM.HideMethodParens || (_argumentVMs != null && _argumentVMs.Count > 0))
                renderer.RenderText(!MethodDeclBaseVM.HideMethodParens ? Call.ParseTokenStart : " ", brush, this);
        }

        protected override void RenderEndArguments(CodeRenderer renderer, Brush brush, RenderFlags flags)
        {
            if (!MethodDeclBaseVM.HideMethodParens)
            {
                if (Call.IsEndFirstOnLine)
                    renderer.NewLine();
                renderer.RenderText(Call.ParseTokenEnd, brush, this);
            }
        }

        public override void RenderToolTip(CodeRenderer renderer, RenderFlags flags)
        {
            base.RenderToolTip(renderer, flags);
            Expression invokeRef = _expressionVM.Expression.SkipPrefixes();
            if (invokeRef is ConstructorRef)
            {
                renderer.NewLine();
                CreateVM(invokeRef).RenderToolTip(renderer, RenderFlags.SuppressLineCol);
            }
        }

        #endregion
    }
}
